package com.dai.zhenfujin.visitingcard.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dai.zhenfujin.R;
import com.dai.zhenfujin.bean.ColleagueListBean;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

public class ColleagueAdapter extends BaseAdapter {

    private Context context;
    private List<ColleagueListBean.UserListBean> beans;
    private LayoutInflater inflater;

    public ColleagueAdapter(Context context, List<ColleagueListBean.UserListBean> beans) {
        this.context = context;
        this.beans = beans;
        inflater = LayoutInflater.from(context);
    }


    @Override
    public int getCount() {
        return beans.size();
    }

    @Override
    public Object getItem(int position) {
        return beans.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.colleague_listview,null);
            holder. mColleague_imageview_one = (CircleImageView)convertView. findViewById(R.id.colleague_imageview_one);
            holder. mColleague_item_name = (TextView)convertView. findViewById(R.id.colleague_item_name);
            holder. mColleague__item_post = (TextView)convertView. findViewById(R.id.colleague__item_post);
            holder. mColleague_item_distance = (TextView)convertView. findViewById(R.id.colleague_item_distance);
            holder. mColleague_item_company = (TextView)convertView. findViewById(R.id.colleague_item_company);
            holder. mColleague_item_work = (TextView)convertView.findViewById(R.id.colleague_item_work);

            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.mColleague_item_name.setText(beans.get(position).getUser_name());
        holder.mColleague__item_post.setText(beans.get(position).getUser_job());
        holder.mColleague_item_distance.setText(beans.get(position).getDist() + "米");
        holder.mColleague_item_company.setText(beans.get(position).getUser_company());
        holder.mColleague_item_work.setText(beans.get(position).getUser_duties());
        Glide.with(context).load(beans.get(position).getUser_logo()).into(holder.mColleague_imageview_one);
        return convertView;
    }

    class ViewHolder{
        private CircleImageView mColleague_imageview_one;
        private TextView mColleague_item_name;
        private TextView mColleague__item_post;
        private TextView mColleague_item_distance;
        private TextView mColleague_item_company;
        private TextView mColleague_item_work;
    }
}
